import bisect
class Solution(object):
    def shortestSubarray(self, nums, k):
        n = len(nums)
        min_len = n + 1
        st = []
        for i in range(1, n):
            nums[i] += nums[i - 1]
        for index, num in enumerate(nums):
            while st and num <= st[-1][0]:
                st.pop()
            id = bisect.bisect_right(st, [num - k, index])
            if id > 0:
                min_len = min(min_len, index - st[id - 1][1])
            if nums[index] >= k:
                min_len = min(min_len, index + 1)
            st.append([num, index])
        if min_len <= n:
            return min_len
        else:
            return -1







data = Solution()
nums = [2,-1,2]
k = 3
print(data.shortestSubarray(nums, k))